//假子弹基础类(紧紧用来演示射击)
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止

module py2Obj {


	export class fakeBullet extends basicObj {
		//保存外部的物理世界

		private bulletType: any;
		public isRun = false;
		public constructor(world: any, gamePanle: any, romveSkins: any) {
			super(world, gamePanle, romveSkins);
			this.objkind = 301;

		}

		public init() {
			super.init();


		}

		public send(x, y, forcex, forcey) {


			this.m_body.type = 1;
			this.isRun = true;
			this.m_body.velocity = [0, 0];
            this.m_body.damping=0.5;
			this.setPostion(x, y);
			this.setForce(forcex, forcey);
			//this.bulletPosition_x=this.m_body.velocity[0];
			// console.log("速度"+this.m_body.velocity);
			// console.log("速度"+this.m_body.velocity[0]);
			// console.log("速度"+this.m_body.velocity[1]);

			// if(this.m_body.velocity[0]==0)
			// {
            //      console.log("速度"+this.m_body.velocity[1]);
			// }
		}
		public createMyRigidbody(): p2.Body {
			var world: P2World = this.m_world;
			var skin: MImage = this.createSkin("ball_png");
			var body: p2.Body = world.createCircleBodyShape(skin.width >> 1);
			body.userData.skin = skin;
			body.userData.data = this;
			body.mass = 0;//质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
			
		    //this.setMaterial()
			var shape = body.shapes[0];
			shape.collisionGroup = 2;//010与001为0，010与110为1
			
			// shape.collisionMask=2;
			// trace(shape.collisionGroup,shape.collisionMask)
			return body;
		}
		private createFixedBullet() {

		}

		public runEnd() {

			var bullet = new py2Obj.basicBullet(this.m_world, this.m_gamePanle, this.m_removeSkins);
			bullet.init();
			bullet.setPostion(this.m_body.position[0], this.m_body.position[1]);
			this.m_gamePanle.doMaterial(bullet.getBody());
			// bullet.setForce(this.vec.x, this.vec.y);
			// this.setChildIndex(this.gun, this.numChildren - 1);
			this.isRun = false;
			this.recyle();

		}

		public recyle() {
			this.m_body.type = 2;
			this.setPostion(-100, -100);
		}
		/**
		 * Body.KINEMATIC = 4;
		 * Body.STATIC = 2;
		 * Body.DYNAMIC = 1;
		 */
		public getCollision(otherBody: basicObj) {

			this.recyle();
			//	this.setPostion(this.m_body.position[0], this.m_body.position[1]);

			this.isRun = false;
		}
	}
}